package saeildamil.ch18.communication;

import javax.swing.JOptionPane;

public class CalcPIThread extends Thread {
	SharedArea sharedArea;

	public CalcPIThread(SharedArea sharedArea) {
		this.sharedArea = sharedArea;
	}
	@Override
	public void run() {
		double total=0.0;
		for(int cnt=1; cnt<1000000000; cnt+=2){
			if(cnt/2%2==0)
				total+=1.0/cnt;
			else
				total-=1.0/cnt;
			}
		sharedArea.result=total*4;
		sharedArea.isReady=true;
		JOptionPane.showMessageDialog(null, sharedArea.result);
		synchronized (sharedArea) {
			JOptionPane.showMessageDialog(null, "대기 중인 PrintThread로 신호 전송");
			sharedArea.notifyAll();	//shareArea에서 wait()에 의해 대기하고 있는 thread에게 신호보냄
		}
			
		
	}
}
